package hy.dao;

import hy.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class UserDao {
    @Autowired
    JdbcTemplate tm;


    public List<User> selectUser() {
        System.out.println(tm.update("delete from t_user"));
        return tm.query("select * from t_user", (r, i) -> new User(r.getLong(1),r.getString(2),r.getInt(3)));
//        RestultSet rs = null;
//        List<User> list = new ArrayList<>();
//        while (rs.hasNext()){
//            User u = new User();
//            u.setName(rs.getLong(1));
//            u.setAge(rs.getInt(3));
//            list.add(u);
//        }
//        return list;
    }
}
